package com.chuangke.login.context;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.chuangke.admin.entity.SysUser;
import com.chuangke.admin.service.SysUserService;
import com.chuangke.common.exception.ChuangkeException;
import com.chuangke.common.utils.SecurityUtils;

import cn.hutool.core.util.StrUtil;

@Component
public class LoginContext {
	
	@Autowired
	private SysUserService sysUserService;

	public String getCurrentUserDept() {
		SysUser sysUser = sysUserService.findById(SecurityUtils.getUserId());
		if (StrUtil.isBlank(sysUser.getDeptId())) {
			throw new ChuangkeException("当前用户未配置所属单位");
		}
		return sysUser.getDeptId();
	}
}
